struct Solution {}

fn main() {}

impl Solution {
    pub fn maximum_triplet_value(nums: Vec<i32>) -> i64 {
        let mut ret: i64 = 0;
        for idx in 1..(nums.len() - 1) {
            let max_front = nums[0..idx].iter().max().unwrap();
            let max_end = nums[(idx + 1)..].iter().max().unwrap();
            let tmp: i64 = Self::cal(max_front, &nums[idx], max_end);
            ret = if tmp > ret { tmp } else { ret };
        }
        ret
    }

    fn cal(x: &i32, y: &i32, z: &i32) -> i64 {
        ((*x as i64) - (*y as i64)) * (*z as i64)
    }
}